package org.txazo.music.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * Annotation工具类
 * 
 * @author Tu XiaoZhou
 * @since 2013-04-12
 * 
 */
public class AnnotationUtil {

	public static <T extends Annotation> T getFromMethedOrType(
			Class<T> annotationClass, Object object, String methodName) {
		if (object == null) {
			return null;
		}

		T annotation = null;
		Class<? extends Object> objectClass = object.getClass();
		try {
			Method method = objectClass.getDeclaredMethod(methodName);
			annotation = method.getAnnotation(annotationClass);
		} catch (NoSuchMethodException | SecurityException e) {
			e.printStackTrace();
		}

		if (annotation != null) {
			return annotation;
		}

		return objectClass.getAnnotation(annotationClass);
	}

}
